﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using Survey.Common.Data;
using Survey.Entity;

namespace Survey.Business.Services
{
    public class ContentTypeFilterValidator : FilterValidatorBase<ContentTypeFilter, int>
    {
        protected override void Init(RuleCollection<ContentTypeFilter> rules) { base.Init(rules); }
    }
    public class ContentTypeValidator : EntityValidatorBase<ContentType, int, IContentTypeDao>
    {
        protected override void Init(RuleCollection<ContentType> rules)
        {
            // string
            rules.For(entity => entity.Name).RequireLengthBetween(0, 250);
            rules.For(entity => entity.Suffix).RequireLengthBetween(1, 250);

            // unique Code
            rules.For(entity => entity.Code).RequireLengthBetween(1, 150)
                .BreakOnError();
            rules.IsUnique(entity => Dao.Find(entity.ID, new ContentTypeFilter { CodeExact = entity.Code }));

            // Delete
            // rules.Assure(IsContentTypeInUse).WhenDeleting();
        }
    }
}